package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;

/**
 * SubjectTypeDTO entity. @author MyEclipse Persistence Tools
 */

public class CSVSubjectTypeDTO extends Object implements IsSerializable, ICSVDTO {

    public static final int SORT_CONST__NAME = 0;
    public static final int SORT_CONST__INITIAL = 1;

    public static final int SORT_CONST__ID = 2;
	

    // Fields    
	private long id;
     private String name;
     private String initial;

     private boolean highlighted;

     

    // Constructors

    /** default constructor */
    public CSVSubjectTypeDTO() {
    }

    
    /** full constructor */
    public CSVSubjectTypeDTO(long id, String name, String initial) {
    	this.id = id;
        this.name = name;
        this.initial = initial;
    }

   
    // Property accessors


    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public String getInitial() {
        return this.initial;
    }
    
    public void setInitial(String initial) {
        this.initial = initial;
    }


	//@Override
	public String toString() {
		String result = "" +
		"[ " + CSVSubjectTypeDTO.class + "]" +
		"name: " + name + 
		", initial: " + initial
		;
		return result;
	}

	public String toLabel() {
		String result = name + " (" + initial + ")";
		return result;
	}
	
	public String toLabelShort() {
		String result = initial;
		return result;
	}



	public long getId() {
		return id;
	}


	public void setId(long id) {
		this.id = id;
	}
	
	
	public boolean isHighlighted() {
		return highlighted;
	}

	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	
	
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__NAME) {
			return "" + getName();
		} else if (col == SORT_CONST__INITIAL) {
			return "" + getInitial();
		}
		return "no field";
	}


	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

			    final int BEFORE = -1;
			    final int EQUAL = 0;
			    final int AFTER = 1;
			    
			    CSVSubjectTypeDTO obj1;
			    CSVSubjectTypeDTO obj2;
			    if (o1 instanceof CSVSubjectTypeDTO && o2 instanceof CSVSubjectTypeDTO) {

					obj1 = (CSVSubjectTypeDTO) o1;
					obj2 = (CSVSubjectTypeDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__NAME) {
						return obj1.getName().compareTo(obj2.getName());
					} else if (colIndex == SORT_CONST__INITIAL) {
						return obj1.getInitial().compareTo(obj2.getInitial());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}






}